<template>
	<view class="box">
		
		<view class="search-box">
			<!-- <my-search :search_bgcolor="'#000000'"></my-search> -->
			<my-search @click="goSreach()"></my-search>
		</view>
		<!-- 轮播图 -->
		<view class="box-swiper">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			  <!-- 循环渲染轮播图的 item 项 -->
			  <swiper-item v-for="(item, i) in swiperList" :key="i">
				  <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
				  <!-- 动态绑定图片的 src 属性 -->
					  <image :src="item.image_src"></image>
				  </navigator>
			  </swiper-item>
			</swiper>
		</view>	
		<!-- 导航 -->
		<view class="box-Nav">
			<view class="Nav-content" v-for="(item) in NavList" :key='item.id' @click="NavItem(item.name)">
				<image :src="item.image_src" class="nav-img" mode=""></image>
			</view>
		</view>
		<!-- 楼层数据 -->
		<view class="box-floor">
			<view class="floor-title" v-for="(item, i) in floorList" :key="i">
				<image :src="item.floor_title.image_src" class="image-title"></image>
				<!-- <view class="floor-content-adjust">
					<view class="floor-content-left" v-for="(item,j) in item.product_list" :key="j">
						<image class="right" :src="item.image_src" :style="{width: item.image_width + 'rpx'}" mode="widthFix"></image>
					</view>
					
					<view v-if="k!=0" class="floor-content-right" v-for="(item,k) in item.product_list" :key="k">
						<image  class="right" :src="item.image_src" :style="{width: item.image_width + 'rpx'}" mode="widthFix"></image>
					</view>
				</view> -->
				<view class="floor-img-box">
				  <!-- 左侧大图片的盒子 -->
				  <navigator class="left-img-box" :url="item.product_list[0].url">
				    <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
				  </navigator>
				  <!-- 右侧 4 个小图片的盒子 -->
				  <view class="right-img-box">
				    <navigator class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" :url='item2.url' v-if="i2 !== 0">
				      <image :src="item2.image_src" mode="widthFix" :style="{width: item2.image_width + 'rpx'}"></image>
				    </navigator>
				  </view>
				</view>
			</view>
			
			
		</view>
	</view>
	
</template>

<script>

import { getSwiper,getNav,getFloor } from '@/config/api.js';
import badgeMix from '@/mixins/tabbar-badge.js'
	
	export default {
		data() {
			return {
				swiperList: [],
				NavList: [],
				floorList: [],
				swiperIndex: '',
				isFlag: false
			}
		},
		mixins: [badgeMix],
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods:{
			async getSwiperList(){
				const {data:res} = await getSwiper()				
				// for (var i = 0; i < res.message.length; i++) {
				// 	this.swiperList.push(res.message[i].image_src)
					this.swiperList = res.message	
				// }
				// console.log(res)
			},
			async getNavList() {
 				const {data:res} =  await getNav()
				this.NavList = res.message
				// console.log(this.NavList);
			},
			NavItem(item){
				if(item === "分类"){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
			async getFloorList(){
				const {data:res} = await getFloor()
				this.floorList = res.message
				
				//重写接口的url路径，符合自己分布的内容
				res.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
					})
				})
				console.log(this.floorList);
			},
			goSreach(){
				console.log("goSreach");
			}
		}
	}
</script>

<style lang="scss">
	// * {
	//    touch-action: none;
	// }
	swiper {
	 height: 330rpx;
	
	 .swiper-item,
	 image {
	   width: 100%;
	   height: 100%;
		}
	}
	.box-Nav {
		display: flex;
		justify-content: space-around;
		margin: 30rpx 0;
		.nav-img {
		    width: 128rpx;
		    height: 140rpx;
		  }
	}
	.floor-title {
		margin: 30rpx 0;
		display: flex;
		flex-direction: column;
		.image-title{
			height: 60rpx;
			width: 100%;
		}
		.floor-img-box {
		  display: flex;
		  padding-left: 10rpx;
		}
		.right-img-box {
		  display: flex;
		  flex-wrap: wrap;
		  justify-content: space-around;
		}
	}
	.search-box {
		//吸顶的效果
		position: sticky;
		top:0;
		z-index: 15;
	}
	
</style>